/*
 * Copyright 2013 Agustina Martinez-Garcia

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package uk.ljmu.qudexapps.swfspreadsheet.domain;

import java.util.ArrayList;
import java.util.List;

//import org.springframework.binding.message.MessageBuilder;
import org.springframework.binding.message.MessageContext;
import org.springframework.binding.validation.ValidationContext;

public class MdSchemaInstance extends MdSchema {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -2451011025514298888L;

	/**
	 * Holds a list of the currently selected metadata elements to include in the spreadsheet
	 */
	private List<VocabularyElement> selectedSchemaElements;
	
	private boolean removed;

	public void setSelectedSchemaElements(List<VocabularyElement> selectedSchemaElements) {
		this.selectedSchemaElements = selectedSchemaElements;
	}

	public List<VocabularyElement> getSelectedSchemaElements() {
		return selectedSchemaElements;
	}

	public MdSchemaInstance(String prefix, String readableName) {
		super(prefix, readableName);
		this.selectedSchemaElements = new ArrayList<VocabularyElement>();
		removed = false;
		
	}
	
	public MdSchemaInstance() {
		super();
		this.selectedSchemaElements = new ArrayList<VocabularyElement>();
		removed = false;
	}

	public void validateSelectMetadataElements(ValidationContext context) {
		@SuppressWarnings("unused")
		MessageContext messages = context.getMessageContext();
		//boolean valid = false;
		//for(VocabularyElement elem : selectedSchemaElements) {
		//	if (elem.isSelected()) {
		//		valid = true;
		//		break;
		//	}
		//}
		//if (!valid) {
		//	messages.addMessage(new MessageBuilder().error().code("selectElements").build());
		//}
	}
	
	public VocabularyElement getElementFromSelectedSchemas(String elementName) {
	    for (VocabularyElement elem : this.selectedSchemaElements) {
		if (elem.getName().equalsIgnoreCase(elementName))
		    return elem;
	    }
	    return null;
	}

	/**
	 * @param removed the removed to set
	 */
	public void setRemoved(boolean removed) {
	    this.removed = removed;
	}

	/**
	 * @return the removed
	 */
	public boolean isRemoved() {
	    return removed;
	}
}
